﻿using Orchard;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Implementation;
using Orchard.Environment.Extensions;

namespace ATTools
{
    [OrchardFeature("ATTools")]
    public class Shapes : IShapeTableProvider
    {
        public void Discover(ShapeTableBuilder builder)
        {
            //Wrap the "Translation_ControlWrapper" around the "Localization", so that one can make translations quikly
            builder.Describe("EditorTemplate")
                .OnDisplaying(displayed =>
                {
                    if (displayed.Shape.Prefix == "Localization" && displayed.Shape.Model.MasterContentItem != null)
                    {
                        displayed.Shape.Metadata.Wrappers.Add("Translation_ControlWrapper");
                    }
                });
        }

        public void Creating(ShapeCreatingContext context)
        {
        }

        public void Created(ShapeCreatedContext context)
        {
            if (context.ShapeType == "Parts_Localization_ContentTranslations_Edit")
            {
                context.Shape.Metadata.Wrappers.Add("Translation_ControlWrapper");
            }

        }

    }

    [OrchardFeature("ATTools.VoiceCommands")]
    public class ShapesVoiceCommands : IShapeTableProvider
    {
        public void Discover(ShapeTableBuilder builder)
        {
            //Wrap the "SpeechCommentArea_ControlWrapper" around the "Parts_Comments", so that one can use speech on the comment textarea
            builder.Describe("Parts_Comments")
            .OnDisplaying(displayed =>
            {
                displayed.Shape.Metadata.Wrappers.Add("SpeechCommentArea_ControlWrapper");
            });

        }

        public void Creating(ShapeCreatingContext context)
        {
        }

        public void Created(ShapeCreatedContext context)
        {
        }

    }
}